var mysql = require('mysql');
// 设置连接信息
var connection = mysql.createConnection({
  host: '127.0.0.1',
  user: 'root',
  password: 'root',
  database: 'node'
});

// 连接数据库
connection.connect();

// 执行SQL语句
// 参数3是此次连接的信息
connection.query('select * from users where id = 1', function (error, results, fields) {
  console.log(error);
  console.log('------');
  console.log(results);
  console.log('------')
  console.log(fields);
})

// 关闭信息
connection.end();